﻿using System;
using System.Drawing;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using StedySoft.SenseSDK;
using StedySoft.SenseSDK.DrawingCE;

namespace SenseTimeTracker.CommonSenseControls
{
	public class CommonSenseDisplayPanelItem : SenseListControl.ISenseListItem
	{
		protected bool selected = false;
		protected bool displaySeparator = true;
		protected string name = Guid.NewGuid().ToString();
		protected bool visible = true;
		private int height;

		public CommonSenseDisplayPanelItem()
		{
			RequestAction += CommonSenseDisplayPanelItem_RequestAction;
		}

		void CommonSenseDisplayPanelItem_RequestAction(SenseListControl.ISenseListItem sender, SenseListControl.RequestActionEventArgs e)
		{
		}

		public bool DisplaySeparaor
		{
			get { return displaySeparator; }
			set { displaySeparator = value; }
		}

		public bool IsSelected
		{
			get { return selected; }
		}

		#region ISenseListItem Members

		public List<SenseListControl.ISenseListItem> Children
		{
			get
			{
				return null;
			}
			set
			{
			}
		}

		public Rectangle ClientRectangle
		{
			get;
			set;
		}

		public int Height
		{
			get { return height; }
			set { height = value; }
		}

		public int Index
		{
			get;
			set;
		}

		public void OnGotFocus(int x, int y)
		{
			selected = true;
			UpdateItem();
		}

		public void OnHandleCreated()
		{
		}

		public void OnHandleDisposed()
		{
		}

		public void OnLostFocus(int x, int y)
		{
			selected = false;
			UpdateItem();
		}

		private void UpdateItem()
		{
			SenseListControl.RequestActionHandler myEvent = RequestAction;
			if (myEvent != null)
			{
				myEvent(this, new SenseListControl.RequestActionEventArgs("INVALIDATE"));
			}
		}

		public void OnMouseDown(int x, int y, ref bool cancel)
		{
		}

		public void OnMouseMove(int x, int y)
		{
		}

		public void OnMouseUp(int x, int y)
		{
		}

		public virtual void OnRender(Graphics g)
		{
			using (Pen pen = new Pen(Color.Gray))
			{
			  g.DrawLine(pen, ClientRectangle.Left, ClientRectangle.Bottom, ClientRectangle.Right, ClientRectangle.Bottom);
			}
		}

		virtual public void OnResize()
		{
		}

		public event SenseListControl.RequestActionHandler RequestAction;

		public event SenseListControl.RequestParentHandler RequestParent;

		public object Tag
		{
			get;
			set;
		}

		public int Width
		{
			get;
			set;
		}

		#endregion

		#region ISenseListItem Members


		public string Name
		{
			get { return name; }
			set { name = value; }
		}

		public bool Visible
		{
			get { return visible; }
			set { visible = value; }
		}

		#endregion

		#region ISenseListItem Members


		public bool Enabled
		{
			get
			{
				return true;
			}
			set
			{
				
			}
		}

		#endregion
	}
}
